<template>
  <el-container>
    <!--侧边栏-->
    <el-aside width="200px">
      <SideMenu/>
    </el-aside>
    <el-container>
      <!--头部部分-->
      <el-header>
        <!--头部标题-->
        <strong>后台管理系统</strong>
        <div class="header-avatar">
          <!--头像-->
          <el-avatar size="medium" :src="require('@/assets/tou.jpeg')"></el-avatar>
          <!--下拉框-->
          <el-dropdown>
            <span class="el-dropdown-link">
              {{ userinfo.username }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="toUserCenter">
                  个人中心
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!--网站-->
          <el-link href="http://43.138.224.12:5679/" target="_blank">客家</el-link>
          <el-link href="https://www.bilibili.com/" target="_blank">B站</el-link>
        </div>
      </el-header>
      <!--中间部分-->
      <el-main>
        <!--动态标签页-->
        <Tabs/>
        <div style="margin: 0 15px;">
          <router-view/>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import router from "@/router";
import Tabs from "@/views/inc/Tabs.vue";
import SideMenu from "@/views/inc/SideMenu.vue";
export default {
  name: "Home",
  components: {
    SideMenu, Tabs
  },
  data() {
    return {
      userinfo: {
        id: "",
        username: ""
      }
    }
  },
  /*页面初始化*/
  created() {
    this.getUserInfo()
  },
  methods: {
    getUserInfo() {
      this.$axios.get("/sys/userInfo")
          .then(res => {
            this.userinfo = res.data.data
          })
    },
    logout() {
      this.$axios.post("/logout")
          .then(res => {
            /*清除本地域及vuex中的信息,然后跳转至登录页面*/
            localStorage.clear()
            sessionStorage.clear()
            /*重置路由*/
            /*this.$store.commit("resetState")*/
            this.$router.push("/login")
          })
    },
    toUserCenter() {
      this.$router.push("/userCenter")
      let item = {
        title: "个人中心",
        name: "UserCenter"
      }
      this.$store.commit('addTab', item)
    }
  }
}
</script>

<style scoped>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}
.header-avatar {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.el-dropdown-link {
  cursor: pointer;
  color: rgba(214, 64, 255, 0.72);
}
.el-icon-arrow-down {
  font-size: 12px;
}

.el-header {
  background-color: #cbd1b3;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: rgba(171, 20, 68, 0.77);
  color: #333;
  line-height: 200px;
}

.el-main {
  color: #333;
  /*  text-align: center;*/
  padding: 0;
  /* line-height: 160px;*/
}
/*去掉下划线*/
a {
  text-decoration: none;
}
</style>
